/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.fieo.sgee.model;

import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author Claudete
 */
@Entity
@Table(name = "kwhs")
@NamedQueries({
    @NamedQuery(name = "Kwh.findAll", query = "SELECT k FROM Kwh k"),
    @NamedQuery(name = "Kwh.findById", query = "SELECT k FROM Kwh k WHERE k.id = :id"),
    @NamedQuery(name = "Kwh.findByValor", query = "SELECT k FROM Kwh k WHERE k.value = :value"),
    @NamedQuery(name = "Kwh.findByMes", query = "SELECT k FROM Kwh k WHERE k.month = :month"),
    @NamedQuery(name = "Kwh.findByAno", query = "SELECT k FROM Kwh k WHERE k.year = :year"),
    @NamedQuery(name = "Kwh.findByDataCriacao", query = "SELECT k FROM Kwh k WHERE k.created_at = :created_at"),
    @NamedQuery(name = "Kwh.findByDataModificacao", query = "SELECT k FROM Kwh k WHERE k.updated_at = :updated_at")
})
public class Kwh implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Integer id;
    @Basic(optional = false)
    @Column(name = "valor")
    private float value;
    @Basic(optional = false)
    @Column(name = "mes")
    private int month;
    @Basic(optional = false)
    @Column(name = "ano")
    private int year;
    @Basic(optional = false)
    @Column(name = "data_criacao")
    @Temporal(TemporalType.DATE)
    private Date created_at;
    @Basic(optional = false)
    @Column(name = "data_modificacao")
    @Temporal(TemporalType.TIMESTAMP)
    private Date updated_at;

    public Kwh() {
        this.setDateCreation();
    }

    public Kwh(float value) {
        this.setDateCreation();
        this.value = value;
    }

    public float getValue() {
        return value;
    }

    public void setValue(float value) {
        this.value = value;
    }

    /**
     * Método para registrar as datas na nova estimativa
     */
    private void setDateCreation() {
        this.created_at = new Date();
        this.updated_at = new Date();
        this.month = Calendar.getInstance().get(Calendar.MONTH);
        this.year = Calendar.getInstance().get(Calendar.YEAR);
    }

    public Date getCreated_at() {
        return created_at;
    }

    public Integer getId() {
        return id;
    }

    public int getMonth() {
        return month;
    }

    public Date getUpdated_at() {
        return updated_at;
    }

    public int getYear() {
        return year;
    }

}
